package com.orm.handler;

import java.sql.*;
import java.util.Date;


/**
 * java.util.Date  转换 （不是 java.sql.Date)
 */
public class DateTypeHandler extends BaseTypeHandler<Date> {
	
	@Override
	public void setNotNullParameter(PreparedStatement ps, int i, Date parameter, JDBCType jdbcType) throws SQLException {
		ps.setTimestamp(i, new Timestamp(parameter.getTime()));
	}
	
	@Override
	public Date getNullableResult(ResultSet rs, String columnName) throws SQLException {
		Timestamp timestamp = rs.getTimestamp(columnName);
		return timestamp == null ? null : new Date(timestamp.getTime());
	}
	
	@Override
	public Date getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
		Timestamp timestamp = rs.getTimestamp(columnIndex);
		return timestamp == null ? null : new Date(timestamp.getTime());
	}
}
